<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Redis;
class AgentLog extends Model
{
    protected $table = 'agentlog';
    
    /**
     * 是否主动维护时间戳
     *
     * @var bool
     */
    public $timestamps = false;
    
    public static function creditPay($aid,$type,$credit,$remark,$tag=''){
        if (Redis::get('agentcredit'.$aid.$tag."_".$type)) return;
        Redis::setex('agentcredit'.$aid.$tag."_".$type,3,1);
        Agent::where('id',$aid)->increment('credit',$credit);
        AgentLog::insert(array('aid'=>$aid,'type'=>$type,'credit'=>$credit,'remark'=>$remark,'surplus'=>Agent::where('id',$aid)->value('credit'),'createtime'=>time()));
    }
}
